﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StorageManager;
using Astoman.Common;

namespace StorageManagerTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class AzureStorageAccountTests
    {
        public AzureStorageAccountTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void ValidateSetting_Recognizes_Lowercase_Account_Name_And_Base64String_As_Right()
        {
            var correctAccountName = "testaccount";
            var correctSharedKey = "lRVydwwdata1d0fd+8Snx3PdjNhsHxJ+w8nRiyTiZkfMFsGZCDy3E5JhqaWP52HioUoxeXhLLXJvm3hYDevsyQ==";
            var error = AzureStorageAccount.ValidateSetting(correctAccountName, correctSharedKey);
            Assert.IsNull(error);
        }

        [TestMethod]
        public void ValidateSetting_Recognizes_Account_Name_With_Uppercase_Character_As_Wrong()
        {
            var wrongAccountName1 = "Testaccount";
            var wrongAccountName2 = "testAccount";
            var correctSharedKey = "lRVydwwdata1d0fd+8Snx3PdjNhsHxJ+w8nRiyTiZkfMFsGZCDy3E5JhqaWP52HioUoxeXhLLXJvm3hYDevsyQ==";
            
            var error1 = AzureStorageAccount.ValidateSetting(wrongAccountName1, correctSharedKey);
            var error2 = AzureStorageAccount.ValidateSetting(wrongAccountName2, correctSharedKey);

            Assert.IsNotNull(error1);
            Assert.IsTrue(error1.Contains("lowercase"));

            Assert.IsNotNull(error2);
            Assert.IsTrue(error2.Contains("lowercase"));
        }

        [TestMethod]
        public void ValidateSetting_Recognizes_String_With_Wrong_Base64_Format_As_Wrong()
        {
            var correctAccountName = "testaccount";
            var wrongSharedKey = "lRVydwwdata1d0fd+8Snx3PdjNhsHxJ+w8nRiyTiZkfMFsGZCDy3E5JhqaWP52HioUoxeXhLLXJvm3hYDevsyQ=";
            var error = AzureStorageAccount.ValidateSetting(correctAccountName, wrongSharedKey);
            Assert.IsNotNull(error);
            Assert.IsTrue(error.Contains("Base64"));
        }
    }
}
